package br.sales.view.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import br.sales.persistence.DB4OAppSingleton;
import br.sales.persistence.exception.DBContainerNotInitializedException;
import br.sales.util.DBInit;


@WebListener(value="appContextListener")
public class AppContextListener implements ServletContextListener{

	@Override
	public void contextInitialized(ServletContextEvent sce) {
		
		DB4OAppSingleton.getInstance();
		DBInit dbInit = new DBInit();
		dbInit.initConfiguration(true);
		dbInit.initSystemLanguages(false);
		dbInit.initAdmin(true);
		
	}

	@Override
	public void contextDestroyed(ServletContextEvent sce) {
		try {
			DB4OAppSingleton.close();
		} catch (DBContainerNotInitializedException e) {
			e.printStackTrace();
		}
	}


}
